@(query: String, plate: String, list: List[IndexedDocument], page: Int, total: Int)(implicit request: RequestHeader)

@main("欢迎来到社区！", "search") {
<style>
  .fly-list .fly-list-li { height: auto; }
  .fly-list-li h2 a { font-size: 18px; }
  .fly-panel-title a { padding: 0px; }
  .fly-list li {
    position: relative;
    height: 45px;
    line-height: 22px;
    padding: 15px 15px 15px 15px;
    border-bottom: 1px dotted #e2e2e2;
  }
  p.content { color: #545454; font-size: 13px; }
</style>
<div class="layui-container">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <form action="/search" >
        <div class="layui-form">
          <div class="layui-inline">
            <input id="q" type="text" name="q" value="@query" required lay-verify="required" placeholder="请输入搜索内容" autocomplete="off" class="layui-input" style="width:300px;">
          </div>
          <div class="layui-inline">
            <div class="layui-btn-group">
              <button class="layui-btn">站内搜索</button>
              <!--<button class="layui-btn" id="gBtn" type="button">站外搜索</button>-->
            </div>
          </div>
        </div>
      </form>

      <div class="fly-panel" style="margin-bottom: 0;">
        <div class="fly-panel-title fly-filter">
          <a class="layui-this">搜索结果(@total)</a>
        </div>

        <ul class="fly-list">
          @for(a <- list){
          <li class="fly-list-li">
            @if(a.plate == "book"){
            <h2 class="fly-tip">
              <a target="_blank" href='http://www.playscala.cn/book/@{a.bookInfo.get.bookId}/index.html#pf@{a.bookInfo.get.pageFrom.toHexString}' style="color: #009688;">@Html(a.title)</a>
            </h2>
            <p class="content">
              @Html(a.hlContent.getOrElse(a.content.take(100) + "..."))
            </p>
            <p>
              <span><a target="_blank" href='http://www.playscala.cn/book/@{a.bookInfo.get.bookId}/index.html'>@a.bookInfo.get.bookName</a></span>
              <span>@a.bookInfo.get.parentCatalog.replace("/", " / ")</span>
              <span>@{a.bookInfo.get.pageFrom}-@{a.bookInfo.get.pageTo}</span>
            </p>
            } else {
            <h2 class="fly-tip">
              <a href="/@{a.plate}/view?_id=@a.id" style="color: #009688;">@Html(a.title)</a>
            </h2>
            <p>
              <span><a href="/user/home?uid=@{a.authorId}">@a.author</a></span>
              <span>@utils.DateTimeUtil.toPrettyString(a.createTime)</span>
              <span>@utils.AppUtil.prettyResource(a.plate)</span>
            </p>
            }
          </li>
          }
        </ul>
        <div style="text-align: center">
          <div class="laypage-main">
            <a href="/search?q=@{query}&page=@{page-1}" class="laypage-prev">上一页</a><span>@{if(list.isEmpty){1}else{page}}/@{math.ceil(total/15.0).toInt}</span><a href="/search?q=@{query}&page=@{page+1}" class="laypage-next">下一页</a></div>
        </div>
      </div>
    </div>
  </div>
</div>
}

<script>
$('#gBtn').click(function(){
  var val = $('#q').val();
  if(val.replace(/\s/g, '') === ''){
    return ;
  }
  window.location.href = "https://search.playscala.cn/search?q=" + val;
});
</script>
